package com.hustzp.com.xichuangzhu.dao;

import android.content.Context;

import com.hustzp.com.xichuangzhu.model.CollectionKinds;
import com.hustzp.com.xichuangzhu.model.Collections;
import com.hustzp.com.xichuangzhu.utils.DBHelper;
import com.j256.ormlite.stmt.QueryBuilder;

import java.util.List;

/**
 * Copyright (C) 2015 The huimai mobile client Project
 * All right reserved.
 *
 * @author: wuzhimin@huimai365.com
 * @date: 2016/5/27 21:47
 * @Description:
 */
public class CollectionKindsDao {
    private Context context;
    private DBHelper helper;

    public CollectionKindsDao(Context context) {
        this.context = context;
        try {
            helper = DBHelper.getInstance(context);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public List<CollectionKinds> getCollectioinKinds() {
        try {
            List<CollectionKinds> users = helper.getDao(CollectionKinds.class).queryForAll();
            return users;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public List<Collections> getCollectioins(CollectionKinds kinds) {
        try {
            QueryBuilder<Collections, Integer> builder = (QueryBuilder<Collections, Integer>) helper.getDao(Collections.class).queryBuilder();
            builder.where().eq("kind_id", kinds.getId());
            builder.orderBy("show_order", true);
            List<Collections> users = helper.getDao(Collections.class).query(builder.prepare());
            return users;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }


}
